#include "all_lib.h"
#pragma hdrstop

#if defined(__GNUC__)
  #include "Std/xfuncs.inc"
#endif

#include <Global/pack1.h>
STRUCT( WTmpInfo )
  char  Type[ 8 ];
  char  Name[ 16 ];
  char  Addr[ 16 ];
  DWORD Time;
};
#include <Global/pop.h>

int main( int argc,char *argv[] )
  {
    CTArgInit(argc,argv,FALSE);

    if (argc < 2 || CTArgCheck("?") ) {
      printf( "USAGE: wtmpU <wtmp file>\n" );
      return 0;
    }

    CONSTSTR m = CTArgGetArg(0);
    printf( "Reading file: %s...\n", m );

    int f = FIO_OPEN( m, O_RDONLY );
    if ( f == -1 )
      HAbort( "!open source file" );

    int n;
    for( n = 0; 1; n++ ) {
      WTmpInfo it;
      char     sbuff[ 100 ];

      if ( FIO_READ( f, &it, sizeof(it) ) != sizeof(it) )
        break;

      strftime( sbuff, sizeof(sbuff),"%d/%m/%Y %H:%M:%S",localtime((time_t*)&it.Time) );
      printf( "%3d) %-*s %-*s %-*s - %s\n",
              n+1,
              sizeof(it.Type)+2, it.Type,
              sizeof(it.Name)+2, it.Name,
              sizeof(it.Addr)+2, it.Addr,
              sbuff,
              0 );

    }
    printf( "Total %d entry read\n", n );

 return 0;
}
